<{extend name="base" /}>
<{block name="body"}>
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">后台菜单</li>
            <li class=""><a href="<{:url('admin/menu/add')}>">添加菜单</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show layui-form">
                <button class="layui-btn" onclick="delchecked()">删除所选</button>
                <table class="layui-table">
                    <thead>
                    <tr>
                        <td>
                            <input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose">
                        </td>
                        <th style="width: 30px;">ID</th>
                        <th style="width: 30px;">排序</th>
                        <th>菜单名称</th>
                        <th>控制器方法</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <{foreach name="admin_menu_level_list" item="vo"}>
                    <tr>
                        <td>
                            <input type="checkbox" name="ids[]" value="<{$vo.id}>" lay-skin="primary" lay-filter="itemChoose">
                        </td>
                        <td><{$vo.id}></td>
                        <td><{$vo.sort}></td>
                        <td><{neq name="vo.level" value="1"}>|<{php}>for($i=1;$i<$vo['level'];$i++){echo ' ----';}<{/php}><{/neq}> <{$vo.title}></td>
                        <td><{$vo.name}></td>
                        <td><{php}>echo $vo['status']==1 ? '显示' : '隐藏';<{/php}></td>
                        <td>
                            <a href="<{:url('admin/menu/add',['pid'=>$vo['id']])}>" class="layui-btn layui-btn-mini">添加子菜单</a>
                            <a href="<{:url('admin/menu/edit',['id'=>$vo['id']])}>" class="layui-btn layui-btn-normal layui-btn-mini">编辑</a>
                            <a href="<{:url('admin/menu/delete',['id'=>$vo['id']])}>" class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                        </td>
                    </tr>
                    <{/foreach}>
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<{/block}>
<{block name="script"}>
<script type="text/javascript">

    form.on('checkbox(allChoose)', function(data){
        var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
        child.each(function(index, item){
            item.checked = data.elem.checked;
        });
        form.render('checkbox');
    });
    form.on('checkbox(itemChoose)',function(data){
        var sib = $(data.elem).parents('table').find('tbody input[type="checkbox"]:checked').length;
        var total = $(data.elem).parents('table').find('tbody input[type="checkbox"]').length;
        if(sib == total){
            $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked",true);
            form.render();
        }else{
            $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked",false);
            form.render();
        }
    });
    function delchecked() {
        layer.confirm('小心删除啊。。删了就没了', <{icon: 3, title:'提示'}, function(index){
          val = $("input:checkbox[name='ids[]']:checked");
            data = [];
            val.each(function(i){
               data[i]= $(this).val();
            })
            $.ajax({
                url:"<{:url('admin/menu/deleteall')}>",
                method:'POST',
                data:'ids='+data.toString(),
                dataType:'json',
                success:function(e){
                    window.location.href = window.location.href;
                }
            });
          layer.close(index);
        });

    }
</script>
<{/block}>
